if condition ! falsy value


Posted by mijouhsieh on 2023-03-27

// 錯誤寫法
if(!movies || !(movies.length === 0 )) { return }

正確寫法
if(!movies || !movies.length) return

movies.length若為0 就是 false
!false 就是 true
所以不用寫(movies.length === 0)

return 在同一行,不用寫{}


#|| #OR operator #! #debug







Related Posts

【Day03】列表渲染 & 表單綁定

【Day03】列表渲染 & 表單綁定

交叉編譯準備工作(一)

交叉編譯準備工作(一)

DAY7:Count by X

DAY7:Count by X


Comments